package com.woniuxy.platform.core.controller;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.common.CommonResult;
import com.woniuxy.platform.core.model.PmEvaluate;
import com.woniuxy.platform.core.service.PmEvaluateService;
import com.woniuxy.platform.core.vo.EvaluateVo;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author gmx
 * @since 2021-06-30
 */
@RestController
@RequestMapping("pmEvaluate")
public class PmEvaluateController {

    @Resource
    public PmEvaluateService evaluateService;
    /**
     * Description : 评价订单
     * ChangeLog : 1. 创建 (2021/7/2 10:05 [fulang]);
     * @param evaluate
     * @return com.woniuxy.common.CommonResult
    */
    @ApiOperation(value = "评价订单")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "评价内容",name ="context"),
            @ApiImplicitParam(value = "评价分",name = "score"),
            @ApiImplicitParam(value = "订单id",name = "orderId"),
            @ApiImplicitParam(value = "创建时间",name = "createtime")
    }
    )
    @ApiResponses({
            @ApiResponse(code = 200,message = "评价成功"),
            @ApiResponse(code = 500,message = "评价失败")
    })
    @PostMapping("evaluate")
        public CommonResult insert(@RequestBody PmEvaluate evaluate){
        evaluate.setCreatetime(new Date());
            int i = evaluateService.insert(evaluate);
            if (i>0){
                return CommonResult.success();
            }
            return CommonResult.fail("评价失败");
        }
        /**
         * Description : 所有评价列表
         * ChangeLog : 1. 创建 (2021/7/12 14:11 [fulang]);
         * @param startpage
         * @param pagesize
         * @return com.github.pagehelper.PageInfo<com.woniuxy.platform.core.model.PmEvaluate>
        */
    @GetMapping("list/{startpage}/{pagesize}")
    public PageInfo<EvaluateVo> list(@PathVariable int startpage, @PathVariable int pagesize){
        PageHelper.startPage(startpage,pagesize);
        List<EvaluateVo> list = evaluateService.evalist();
        Page page = (Page) list;
        PageInfo<EvaluateVo> pageInfo = new PageInfo<>(page);
        return pageInfo;
    }
    /**
     * Description : 查看商品评价
     * ChangeLog : 1. 创建 (2021/7/13 15:02 [fulang]);
     * @param startpage
     * @param pagesize
     * @return com.github.pagehelper.PageInfo<com.woniuxy.platform.core.vo.EvaluateVo>
    */
    @GetMapping("goods/{startpage}/{pagesize}")
    public PageInfo<EvaluateVo> goods(@PathVariable int startpage, @PathVariable int pagesize){
        PageHelper.startPage(startpage,pagesize);
        List<EvaluateVo> list = evaluateService.goods();
        Page page = (Page) list;
        PageInfo<EvaluateVo> pageInfo = new PageInfo<>(page);
        return pageInfo;
    }
    /**
     * Description : 查看服务评价
     * ChangeLog : 1. 创建 (2021/7/13 15:02 [fulang]);
     * @param startpage
     * @param pagesize
     * @return com.github.pagehelper.PageInfo<com.woniuxy.platform.core.vo.EvaluateVo>
    */
    @GetMapping("service/{startpage}/{pagesize}")
    public PageInfo<EvaluateVo> service(@PathVariable int startpage, @PathVariable int pagesize){
        PageHelper.startPage(startpage,pagesize);
        List<EvaluateVo> list = evaluateService.service();
        Page page = (Page) list;
        PageInfo<EvaluateVo> pageInfo = new PageInfo<>(page);
        return pageInfo;
    }
}

